﻿@{
    Page.Title = "Change Password";
    var errMSG = "";
    var fPwd = "";
    var sPwd = "";
    var rcUser = User.Identity.Name.ToString();    
    
    Validation.RequireField("fPwd","Enter new password");
    Validation.RequireField("sPwd","Confirm new password");
    Validation.Add("fPwd", Validator.StringLength(30,6,"Minimum length: 6"));
    Validation.Add("sPwd", Validator.EqualsTo("fPwd","Passwords must match!"));

    fPwd=Request["fPwd"];
    sPwd = Request["sPwd"];

    if (IsPost && Validation.IsValid()){
               
        var db = Database.Open("razorC");
        var sqlUp = "Update rc_Login set rcPwd=@0 where rcUser=@1";
        try
        {
            db.Execute(sqlUp, fPwd, rcUser);
            errMSG = "<b>Thank You - changes saved !</b>";
        }
        catch (Exception ex)
        {

            errMSG = ex.Message.ToString();
        }
        
      
    }
}

@section head {
    
}
@section menu{
@RenderPage("_Menu.cshtml")
}
@if (!errMSG.IsEmpty())
{
<div> 
@Html.Raw(errMSG)
</div>
}
<form method="post" action="">
 <fieldset>
        <legend>User: @rcUser</legend>
        <ol>
            <li >
                <label for="fPwd">New Password:</label>
                <input type="password" name="fPwd" id="fPwd" value="@fPwd" maxlength="50" @Validation.For("fPwd") />
                @Html.ValidationMessage("fPwd")
                </li>
                <li>
                <label for="sPwd">Password Again:</label>
                <input type="password" name="sPwd" id="sPwd" value="@sPwd" maxlength="50" @Validation.For("sPwd") />
                    @Html.ValidationMessage("sPwd")
            </li>
        </ol>
          <p class="form-actions">
            <input type="submit" value="Change" title="Change" />
        </p>
</fieldset>
</form>
